import { Body, Controller, Delete, Get, Param, Post, Put, UseGuards } from '@nestjs/common'
import { CartService } from './cart.service'
import { Cart } from '../entities/cart.entity'
import { AuthGuard } from '../common/guard/auth.guard'
import { ApiOperation, ApiTags } from '@nestjs/swagger'

@ApiTags('购物车')
@Controller('cart')
@UseGuards(AuthGuard)
export class CartController {
  constructor(private readonly cartService: CartService) {}

  // 添加
  @ApiOperation({ summary: '添加商品到购物车' })
  @Post()
  save(@Body() cart: Cart) {
    return this.cartService.save(cart)
  }

  // 查询用户购物车的所有记录
  @ApiOperation({ summary: '查询购物车中商品' })
  @Get(':uid')
  queryAll(@Param('uid') uid) {
    return this.cartService.queryAll(uid)
  }

  // 修改
  // localhost:3000/cart/10/10
  @ApiOperation({ summary: '修改购物车商品' })
  @Put(':id/:num')
  edit(@Param() param) {
    return this.cartService.edit(param)
  }

  // 删除
  @ApiOperation({ summary: '删除购物车商品' })
  @Delete(':id')
  del(@Param('id') id) {
    return this.cartService.del(id)
  }
}
